package com.dmz.workflow.controller;

import com.dmz.workflow.req.ChitchatReq;
import com.dmz.workflow.util.ObjectUtils;
import com.echronos.commons.Result;

import com.echronos.imc.api.resp.ImcSessionResp;
import com.dmz.workflow.entity.ProcessRelations;
import com.dmz.workflow.service.ProcessDefinitionService;
import com.dmz.workflow.service.WorkflowProcessRelationsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 建群讨论
 **/
@Slf4j
@RestController
@RequestMapping("/v1/flowable/processDefinitionIdentityLink")
public class ProcessImController {

    @Autowired
    private ProcessDefinitionService processDefinitionService;

    @Autowired
    private WorkflowProcessRelationsService workflowProcessRelationsService;

    /**
     * 创建流程讨论群聊
     */
    @PostMapping(value = "/createChitchat")
    public Result<?> createChitchat(@RequestBody ChitchatReq chitchatReq) {
        return processDefinitionService.createChitchat(chitchatReq);
    }

    /**
     * 获取流程会话ID
     * @param processInstanceId 流程实例ID
     * @return 流程的会话ID
     */
    @GetMapping(value = "/queryProcessSessionId")
    public Result<Integer> queryProcessSessionId(@RequestParam String processInstanceId) {
        ProcessRelations processRelations = workflowProcessRelationsService.queryProcessSessionId(processInstanceId);
        return Result.build(ObjectUtils.isNotEmpty(processRelations) ? processRelations.getSessionId() : null);
    }
}
